local LifeManager = {}
LifeManager.mt = { __index = LifeManager }
setmetatable(LifeManager, LifeManager.mt)

function LifeManager:initialize()
	--local lm = {}
	--setmetatable(lm, LifeManager.mt)
	self.lifeforms = {}
	self.humans = {}
	--return lm
end


function LifeManager.new()
	local o = LifeManager.initialize()	
	return o
end

function LifeManager.spawn_role( LifeManager, position, spc, ship )

	local spawns = {
		['captain'] = function(spc, ship) 
			local capt = Captain.new( spc, ship, true)
			return capt
		end,
	
	}
	
	local spawn = spawns[position](spc, ship)
	
	local catalog_spawn = {
		['human'] = function ( life )
			
			local iter = LifeManager:add_human( life )
			LifeManager.humans[iter].human_id = iter
			
			return LifeManager.humans[iter]
		end,
	
	
	}
	
	local spawn2 = catalog_spawn[spc](spawn)
	
	local spawn_id = LifeManager:add(spawn2)
	LifeManager.lifeforms[spawn_id].id = spawn_id
	
	
	
	return LifeManager.lifeforms[spawn_id]

end

function LifeManager:get_humans()

	

end

function LifeManager:get( id )

	return self.lifeforms[id]

end

function LifeManager:add( life )
	local iter = #self.lifeforms+1
	self.lifeforms[iter] = life
	return iter
end

function LifeManager:add_human( life )
	local iter = #self.humans+1
	self.humans[iter] = life
	return iter
end

function LifeManager:remove( life_id )

	table.remove(self.lifeforms, life_id)

end

function LifeManager:remove_human( human_id )
	
	table.remove(self.humans, human_id)

end

function LifeManager:refresh_time()
	for i = 1, #self.lifeforms do
	
		local lf = self.lifeforms[i]
		lf:refresh_time()
	
	end

end

return LifeManager